home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Str / c / strdup < prev    next >
Text File  |  1995-07-08  |  1KB  |  44 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Str.strdup.c
  12.     Author:  Copyright © 1994 Tim Browse
  13.     Version: 1.00 (06 Mar 1994)
  14.     Purpose: Make a copy of a 0-terminated string.
  15. */
  16.  
  17. #include <string.h>
  18. #include <stdlib.h>
  19.  
  20. #include "DeskLib:Str.h"
  21.  
  22. char *strdup(const char *src)
  23. {
  24.   int   len;
  25.   char *dest;
  26.  
  27.   if (src == NULL)
  28.     return NULL;
  29.  
  30.   len = strlen((char *) src) + 1;
  31.  
  32.   dest = (char *) malloc(len);
  33.  
  34.   if (dest == NULL)
  35.     return NULL;
  36.  
  37.   memcpy(dest, src, len-1);
  38.  
  39.   /* make sure string is zero terminated */
  40.   dest[len-1] = (char) 0;
  41.  
  42.   return dest;
  43. }
  44.